/*
//  Copyright © 2014 Allen County Public Library.

  //        ACPL Mobile is free software: This program is distributed and you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.  ACPL Mobile is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, including without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ACPL Mobile. If not, see http://www.gnu.org/licenses/.
 * Author: James Harpe
 * 
 * 
 * Description: This activity displays detailed information about a library location.
 * 
 */

package us.in.lib.acpl.Mobile_ACPL;


import com.google.analytics.tracking.android.EasyTracker;

import us.in.lib.acpl.Mobile_ACPL.adapters.LocationDetailAdapter;
import us.in.lib.acpl.Mobile_ACPL.context.Mobile_ACPL;
import us.in.lib.acpl.Mobile_ACPL.location.LocationInfo;
import us.in.lib.acpl.Mobile_ACPL.parents.BaseListActivity;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public class LocationDetailActivity extends BaseListActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		this.getActionBar().setTitle("  Locations & Hours");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.location_detail);

		displayLocationInfo();

	}
	  @Override
	  public void onStart() {
	    super.onStart();
	    EasyTracker.getInstance().activityStart(this); // Add this method.
	  }

	  @Override
	  public void onStop() {
	    super.onStop();
	    EasyTracker.getInstance().activityStop(this); // Add this method.
	  }

	public void displayLocationInfo() {
		String loc = getIntent().getStringExtra("location");
		TextView t = (TextView) findViewById(R.id.locationLabel);
		t.setText(loc);

		ImageView iv = (ImageView) findViewById(R.id.locationImage);
		iv.setImageResource(LocationInfo.getImageId(loc));

		String[] list = new String[2];
		list[0] = LocationInfo.getAddress(loc);
		list[1] = LocationInfo.getPhone(loc);
		setListAdapter(new LocationDetailAdapter(this, list));
		this.getListView().setOnItemClickListener(new DetailListener());

		String[] hours = LocationInfo.getHours(loc);
		t = (TextView) findViewById(R.id.monHours);
		t.setText(hours[0]);

		t = (TextView) findViewById(R.id.tueHours);
		t.setText(hours[1]);

		t = (TextView) findViewById(R.id.wedHours);
		t.setText(hours[2]);

		t = (TextView) findViewById(R.id.thuHours);
		t.setText(hours[3]);

		t = (TextView) findViewById(R.id.friHours);
		t.setText(hours[4]);

		t = (TextView) findViewById(R.id.satHours);
		t.setText(hours[5]);

		t = (TextView) findViewById(R.id.sunHours);
		t.setText(hours[6]);

		t = (TextView) findViewById(R.id.closedSunday);
		t.setText(hours[7]);
	}

	private class DetailListener implements OnItemClickListener {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			if (position == 0) {
				

				EasyTracker.getTracker().sendEvent("Location", "Address Button Pressed", null, null);
				
				String loc = getIntent().getStringExtra("location");
				Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
						Uri.parse("http://maps.google.com/maps?q="
								+ LocationInfo.getAddress(loc)));
				startActivity(intent);
				

			}
			if (position == 1) {
				
				EasyTracker.getTracker().sendEvent("Location", "Phone Button Pressed", null, null);
				
				String loc = getIntent().getStringExtra("location");
				Intent intent = new Intent(Intent.ACTION_DIAL);
				intent.setData(Uri.parse("tel:" + LocationInfo.getPhone(loc)));
				startActivity(intent);
			}

		}

	}
	


}
